package com.jvyou.common.utils.file;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * OSS图片上传文件的名称的动态拼接
 *
 * @author 橘柚
 * @since 2025-03-07 11:00:41
 */
public class PathUtils {

    public static String generateFilePath(String fileName) {
        //根据日期生成路径   2022/12/3/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/");
        String datePath = sdf.format(new Date());
        //uuid作为文件名
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        //后缀和文件后缀一致
        int index = fileName.lastIndexOf(".");
        // test.jpg -> .jpg
        String fileType = fileName.substring(index);
        return datePath + uuid + fileType;
    }
}
